public class MyTime {
    private int second;
    private int minute;
    private int hour;
    public MyTime(){
        second=0;
        minute=0;
        hour=0;
    }
    public MyTime(int hour){
        this();
        this.hour=hour;
    }
    public MyTime(int hour, int minute){    //在构造函数中可以调用其他构造函数
        this(hour);
        this.minute=minute;
    }
    public MyTime(int hour, int minute, int second){
        this(hour,minute);
        this.second=second;
    }
    public MyTime(MyTime mytime){
        this.hour=mytime.hour;
        this.minute=mytime.minute;
        this.second=mytime.second;
    }
    public void incrementSecond(){
        (this.second)++;
        if (this.second>59){
            this.second=0;
            incrementMinute();
        }
    }
    public void incrementMinute(){
        (this.minute)++;
        if(this.minute>59){
            this.minute=0;
            incrementHour();
        }
    }
    public void incrementHour(){
        (this.hour)++;
        if(this.hour>23){
            this.hour=0;
        }
    }

    @Override
    public String toString() {
        if (!this.isValid(this).isEmpty()) {
            return this.isValid(this);
        }
        int displayHour = this.hour;
        String period = "AM";
        if (displayHour == 0) {
            displayHour = 12;
        } else if (displayHour >= 12) {
            if (displayHour > 12) {
                displayHour -= 12;
            }
            period = "PM";
        }
        return addZero(displayHour) + ":" + addZero(this.minute) + ":" + addZero(this.second) + " " + period;
    }
    public String toUniversalString(){
        if(!this.isValid(this).isEmpty()){
            return this.isValid(this);
        }
        return addZero(this.hour)+":"+addZero(this.minute)+":"+addZero(this.second);
    }
    public String addZero(int value){
        if(value<10){
            return "0"+value;
        }
        else {
            return ""+value;
        }
    }
    public String isValid(MyTime mytime){
        StringBuilder errorNotice=new StringBuilder();
        if(mytime.hour<0||mytime.hour>23) {
            errorNotice.append("hour must be 0-23\n") ;
        }
        if(mytime.minute<0||mytime.minute>59) {
            errorNotice.append("minute must be 0-59\n") ;
        }
        if(mytime.second<0||mytime.second>59) {
            errorNotice.append("second must be 0-59\n") ;
        }
        return errorNotice.toString();
    }
}
